package com.ojoin.trade.supplyloan_core.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ojoin.trade.common.web.controller.BaseController;
import com.ojoin.trade.common.web.controller.BaseControllerImpl;
import com.ojoin.trade.common.web.domain.Result;
import com.ojoin.trade.common.web.service.BaseService;
import com.ojoin.trade.supplyloan_core.constdef.IPlatformUrlDef;
import com.ojoin.trade.supplyloan_core.constdef.IPlatformUrlDef.Statues;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlPlatformInfo;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlPlatformUser;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlPlatformUserVO;
import com.ojoin.trade.supplyloan_core.web.service.TbSlPlatformInfoService;
import com.ojoin.trade.supplyloan_core.web.service.TbSlPlatformUserService;

@Controller
@RequestMapping("/operate/platformuser")
public class SlPlatformUserController extends
		BaseControllerImpl<TbSlPlatformUser> implements
		BaseController<TbSlPlatformUser> {

	private org.slf4j.Logger log = LoggerFactory
			.getLogger(SlPlatformUserController.class);

	@Autowired
	private TbSlPlatformUserService service;

	@Autowired
	private TbSlPlatformInfoService tbSlPlatformInfoService;

	@Override
	protected BaseService<TbSlPlatformUser> getBaseService() {
		return service;
	}

	@ResponseBody
	@RequestMapping(value = "/querysaerch", method = RequestMethod.POST)
	public Result querysaerch() {
		List<String> li = new ArrayList<String>();

		List<TbSlPlatformUser> list = service.queryAll();
		if (null != list) {
			for (int i = 0; i < list.size(); i++) {
				li.add(list.get(i).getPlatformName());
			}
		}
		return new Result(Result.Status.OK, li);
	}

	@ResponseBody
	@RequestMapping(value = "/queryplatformUname", method = RequestMethod.POST)
	public Result queryplatformUname() {
		List<TbSlPlatformInfo> map = tbSlPlatformInfoService
				.queryAllcache();

		return new Result(Result.Status.OK, map);
	}

	@ResponseBody
	@RequestMapping(value = "/queryplatformstatues", method = RequestMethod.POST)
	public Result queryplatformstatues() {
		Map<String,String> map = new HashMap<String,String>();
		Statues[] stas = IPlatformUrlDef.Statues.values();
		if (null != stas) { 
			
			for (int i = 0; i < stas.length; i++) {
				Statues sta = stas[i];
				map.put(sta.getIndex(), sta.getName());
				
			}
		} 
		return new Result(Result.Status.OK, map);
	}

	@ResponseBody
	@RequestMapping(value = "/queryplatformUser", method = {RequestMethod.POST,RequestMethod.GET})
	public Result queryplatformUser(String joinuserid,String  platform_name , String enable_flag ,Pageable page) {
		log.info("joinuserid-->"+joinuserid+"----platform_name-->"+platform_name+"-----enable_flag"+enable_flag);
		List<TbSlPlatformUserVO> li = service.selectPlatformUserListByNameAndFlag(joinuserid, platform_name, enable_flag,page);
		return new Result(Result.Status.OK, li);
	}
	
	
	@ResponseBody
	@RequestMapping(value = "/updateplatformUser", method = {RequestMethod.POST,RequestMethod.GET})
	public Result updateplatformUser(String id ,String enableFlag) {
		log.error("id", id);
		service.updatePlatformUserEnableflagById(Integer.valueOf(id), enableFlag);
		return new Result(Result.Status.OK, "更新成功");
	}
	
}
